//
// Created by 11510 on 2024/6/8.
//
#include <string.h>
#include <unistd.h>
#include <iostream>
#include <fstream>
using std::cin;
using std::cerr;
using std::cout;
using std::endl;
using std::ifstream;
using std::string;

void test0(){
    ifstream ifs;
    ifs.open("main.cpp");
    ifs.clear();

    if(!ifs){
        cerr << "ifstream open file failed" << endl;
    }

#if 0
    // 方式一：兼容C的写法，不常用
    char buff[1 << 10] = {};
    while(ifs.getline(buff, sizeof buff)){
        cout << buff << endl;
        memset(buff, 0, sizeof buff);
    }

    cout << endl;
    ifs.clear();
    if(ifs){
        cout << "new file" << endl;
    }
#endif

    // 方式二：常用
    string line;
    while(std::getline(ifs, line)){
        cout << line << endl;
    }

}


int main() {
    test0();
    return 0;
}